package liecai_class.day02;

import java.util.Arrays;

/**
 * 递归案例 - 全排列
 *
 * 1 -> 1
 * 1,2 -> 1,2 | 2,1
 * 1,2,3 -> 1,2,3 | 1,3,2 | 2,1,3 | 2,3,1 | 3,1,2 | 3,2,1
 * ...
 */
public class Recursion02 {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        fullPermutation(arr,0,2);
    }
    private static void fullPermutation(int[] arr, int start, int end){
        if (start == end){
            System.out.println(Arrays.toString(arr));
            return;
        }
        for (int i=start; i<=end;i++){
            swap(arr,start,i);
            fullPermutation(arr,start+1,end);
            swap(arr,start,i);
        }
    }
    private static void swap(int[] arr, int x, int y){
        int temp = arr[x];
        arr[x] = arr[y];
        arr[y] = temp;
    }
}
